package com.ruoyi.lhky.controller;

import com.ruoyi.lhky.service.ResearchService;
import com.ruoyi.lhky.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/research")
@Tag(name = "研究管理", description = "研究的相关操作")
public class ResearchAppController {

    @Autowired
    private ResearchService researchService;

    @GetMapping("/byUser")
    @Operation(summary = "获取用户相关研究", description = "根据用户ID和工作单位ID获取研究列表")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "400", description = "请求参数错误"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public R listByUserAndWorkplace(@RequestParam Long userId, @RequestParam Long workplaceId) {
        return researchService.listByUserAndWorkplace(userId, workplaceId);
    }

    @GetMapping("/detail")
    @Operation(summary = "获取研究项目详细信息", description = "根据研究项目ID和医院ID获取详细信息")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "400", description = "请求参数错误"),
            @ApiResponse(responseCode = "404", description = "未找到"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public R getResearchDetail(@RequestParam Long researchId, @RequestParam Long hospitalId) {
        return researchService.getResearchDetail(researchId, hospitalId);
    }

    @GetMapping("/participants")
    @Operation(summary = "获取研究项目的参与者", description = "根据研究项目ID和医院ID获取研究项目的参与者")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "400", description = "请求参数错误"),
            @ApiResponse(responseCode = "404", description = "未找到"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public R getParticipants(@RequestParam Long researchId, @RequestParam Long hospitalId) {
        return researchService.getParticipants(researchId, hospitalId);
    }
}
